/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pruebas.npuzzle;

import java.util.Scanner;
import npuzzle.PuzzleNode;

/**
 *
 * @author JULIAN
 */
public class Main {
    public static void main(String args[]){
        new Main().start();
    }
    
    public void start(){
        PuzzleNode pn, temporal=null;
        pn = PuzzleNode.createRandom(4);      
        String option = null;
        do{
            System.out.println(pn);
            System.out.print(String.format("Last moved: %d.(u)p (d)own (l)eft (r)ight (q)uit ? > ", pn.getLastMoved()));
            option = new Scanner(System.in).next();
            switch(option){
                case "u":
                    temporal = pn.move(PuzzleNode.UP);
                    break;
                case "d":
                    temporal = pn.move(PuzzleNode.DOWN);
                    break;
                case "l":
                    temporal = pn.move(PuzzleNode.LEFT);
                    break;
                case "r":
                    temporal = pn.move(PuzzleNode.RIGHT);
                    break;
            }
            if(temporal!=null);
                pn = temporal;
        }while(!"q".equals(option));
    }
    
}
